<?php
namespace App\Api\Controllers;

use Illuminate\Support\Facades\DB;
use Illuminate\Http\Request;

use App\Api\Controllers\BaseController;
use App\Models\Log\LogUserPay;
use App\Api\Service\Trigonal\WxpayService;

use Yansongda\Pay\Pay;

/**
 * 支付类
 * 以下支付后进行的逻辑处理均为充值功能的逻辑代码
 */
class PayController extends BaseController{
    protected $service;

    public function __construct(Request $request){
        parent::__construct($request);
        $this->service = new WxpayService();
    }

    /**
     * 微信小程序支付
     *
     * @param \App\Api\Requests\PayRequest $request
     * @return void
     */
    public function app_pay(\App\Api\Requests\PayRequest $request){
        $integral = $request->input('integral');
        $result = $this->service->pay($this->uid, $integral);
        return $result ? success('支付发起', $result) : error('支付发起失败');
    }

    public function notify(Request $request){
        return $this->service->pay_notify();
    }

    public function pay_contact(\App\Api\Requests\PayContactRequest $request){
        $search_id = $request->input('search_id');
        $type = $request->input('type');
        $result = $this->service->pay_show_contact($this->uid, $search_id, $type);
        return $result ? success('支付发起', $result) : error('支付发起失败');
    }
}
